﻿<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>系统登录 - 超市订单管理系统</title>
    <link type="text/css" rel="stylesheet" href="css/style.css" />
</head>
<body class="login_bg">
    <section class="loginBox">
        <header class="loginHeader">
            <h1>超市订单管理系统</h1>
        </header>
        <section class="loginCont">
	        <form action="view/index.html" class="loginForm">
				<div class="inputbox">
                    <label>用户名：</label>
					<input type="text" class="input-text" id="userCode" name="userCode" placeholder="请输入用户名" required/>
				</div>	
				<div class="inputbox">
                    <label>密码：</label>
                    <input type="password" id="userPassword" name="userPassword" placeholder="请输入密码" required/>
                </div>
                <div class="inputbox" id="errorInfo"></div>
				<div class="subBtn">
                    <input type="submit" value="登录"/>
                    <input type="reset" value="重置"/>
                </div>	
			</form>
        </section>
    </section>

    <script src="js/jquery-3.5.1.js"></script>
    <script src="js/jquery.form.js"></script>
    <script>
        //给表单绑定ajax提交事件
        $("form").ajaxForm({
            url: "user/getUserByLogin",
            type: "post",
            dataType: "json",
            success: function(result){
                if(result != null){
                    //存储用户名到本地
                    localStorage.userName = result.username;
                    //跳转到首页
                    location.href = "view/index.html";
                }else{
                    $("#errorInfo").text("用户名或密码输入错误").css("color","red");
                }
            },
            error: function(xhr){
                alert("请求出错："+xhr.status);
            }
        });

    </script>
</body>
</html>
